import {_, db} from "../cloudbase";

export default class Chips {
    static async add(folder) {
        let collection = db.collection("folders");
        let count = await collection.count();
        count = count.total;
        let folderCount = await collection.where({
            name:_.eq(folder)
        }).count();

        if(folderCount.total > 0){
            alert("文件夹已存在");
            return null;
        }
        if (count >= 20) {
            alert("最大只能添加20个父文件夹");
            return null;
        }
        let addData = {
            name: folder,
            create_time: new Date(),
        };
        let addRes = await collection.add(addData);
        if (addRes) {
            addData._id = addRes.id;
            return addData;
        }
    }
    static async remove(id){
        let collection = db.collection("folders");
        let removeRes = await collection.doc(id).remove();
        if (removeRes) {
            return removeRes;
        }
    }
}